package thread_01;

import java.util.concurrent.CountDownLatch;

public class Demo44 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(10);
        for (int i = 0; i < 10; i++) {
            int id = i;
            Thread t = new Thread(() ->{
                System.out.println("线程启动" + id);
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("线程结束" + id);
                countDownLatch.countDown();
            });
            t.start();
        }
//        await会一直阻塞等待，等到countDownLatch调用次数和构造方法指定次数一致
        countDownLatch.await();
        System.out.println("所以线程结束");


    }
}
